﻿using System;
using System.Collections.Generic;
using System.Text;
using OpenGameEngine;
using OpenGameEngine.Hud;
using OpenGameEngine.Base;

namespace ChopperGame.Scenes.IntroStuff
{
    public class IntroLabel : HudLabel
    {
        public SolidColorBrush TextBrush { get { return new SolidColorBrush(TextColor); } }
        public byte Alpha = 0;
        public Color defaultColor;
        public double _deltaTime;
        public Dictionary<byte, string> IntroText = new Dictionary<byte, string>();
        byte displayId = 0;

        public IntroLabel()
            : base()
        {
            
        }

        public override void Load(GameCoreEventArgs e)
        {
            this.Font = new Font("Comic Sans MS", 50, FontStyle.Normal, FontWeight.Black, FontStretch.Medium);
            this.Text = "MatthiWare Presents";
            defaultColor = this.TextColor;
            this.TextColor = new Color(defaultColor.R, defaultColor.G, defaultColor.B, Alpha);

            IntroText[0] = "MatthiWare Presents";
            IntroText[1] = "Chopper Game";
            IntroText[2] = "Powered by OpenGameEngine";

            base.Load(e);
        }

        public override void Update(OpenGameEngine.Base.GameCoreEventArgs e)
        {
            PreUpdateText(e);

            base.Update(e);

            PostUpdateText(e);

            _deltaTime += e.Time.FrameTime;

            if (_deltaTime >= 0.00075f)
            {
                Alpha += 1;
                _deltaTime = 0;
                this.TextColor = new Color(defaultColor.R, defaultColor.G, defaultColor.B, Alpha);

                if (Alpha == 0)
                {
                    displayId += 1;
                    if (displayId == IntroText.Count)
                        e.Core.SwitchScene("MenuScene");
                }
            }
        }

        private void PreUpdateText(GameCoreEventArgs e)
        {
            this.Text = IntroText[displayId];
        }

        private void PostUpdateText(GameCoreEventArgs e)
        {
            float x, y;
            x = (e.Core.Config.Width / 2) - (this.ActualSize.Width / 2);
            y = (e.Core.Config.Height / 2) - (this.ActualSize.Height / 2);
            this.Position = new Vector2(x, y);
        }
    }
}
